package cn.lingyangwl.agile.food.core.controller.app;

import cn.lingyangwl.agile.food.core.model.rqrs.order.*;
import cn.lingyangwl.agile.food.core.service.*;
import cn.lingyangwl.agile.ram.*;
import cn.lingyangwl.framework.core.response.*;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author shenguangyang
 */
@Api(tags = "订单")
@RestController
@RequestMapping("/app/order")
public class AppOrderController {
    @Resource
    private GoodsOrderService goodsOrderService;

    @GetMapping("/confirmOrder/cart")
    @RamResource(action = "appShop:order:cartConfirmOrder", name = "app-从购物车购买的确认订单", type = ActionType.READ)
    public Resp<CartOrderConfirmResp> confirmCartOrder(@Validated CartOrderConfirmReq req) {
        CartOrderConfirmResp resp = goodsOrderService.cartConfirmOrder(req);
        return Resp.ok(resp);
    }

    @PostMapping("/createOrder/cart")
    @RamResource(action = "appShop:order:createCartOrder", name = "app-创建购物车的订单", type = ActionType.WRITE)
    public Resp<CartOrderResp> saveCartOrder(@RequestBody @Validated CartOrderSaveReq req) {
        CartOrderResp resp = goodsOrderService.saveCartOrder(req);
        return Resp.ok(resp);
    }
}
